/*
 * Copyright 2005-2013 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * Project website:
 *      http://www.cottsoft.com
 */
package com.cottsoft.framework.common.util;

import com.cottsoft.framework.common.flg.IFlg;

/**
 * Class Description: <br> 
 * JVM工具类
 * @author  Simon.Hoo(simon@cottsoft.com)
 * @date    2008年8月11日
 * @version v1.0
 * @since   1.0
 */
public class JvmUtils implements IFlg {

	/**
	 * Java 虚拟机实现供应商
	 */
	private static final String vendor = getJavaVendor();

	/**
	 * Java 运行时环境规范版本
	 */
	private static final float javaVersion = getJavaVersion();

	/**
	 * Description：<br>
	 * 判断录前JVM版本是否不低于1.4
	 * 
	 * @return true/false
	 */
	public static boolean isNotLessThan14() {
		return (javaVersion >= 1.4F);
	}

	/**
	 * Description：<br>
	 * 判断录前JVM版本是否不低于1.5
	 * 
	 * @return true/false
	 */
	public static boolean isNotLessThan15() {
		return (javaVersion >= 1.5F);
	}

	/**
	 * Description：<br>
	 * 判断录前JVM版本是否不低于1.6
	 * 
	 * @return true/false
	 */
	public static boolean isNotLessThan16() {
		return (javaVersion >= 1.6F);
	}

	/**
	 * Description：<br>
	 * 判断录前JVM版本是否不低于1.7
	 * 
	 * @return true/false
	 */
	public static boolean isNotLessThan17() {
		return (javaVersion >= 1.7F);
	}

	/**
	 * Description：<br>
	 * 判断录前JVM版本是否不低于1.8
	 * 
	 * @return true/false
	 */
	public static boolean isNotLessThan18() {
		return (javaVersion >= 1.8F);
	}

	/**
	 * Description：<br>
	 * 获取当前Java 虚拟机实现供应商
	 * 
	 * @return 当前Java 虚拟机实现供应商
	 */
	public static final String getJavaVendor() {
		return System.getProperty("java.vm.vendor");
	}

	/**
	 * Description：<br>
	 * 获取Java 运行时环境规范版本
	 * 
	 * @return Java 运行时环境规范版本
	 */
	public static final float getJavaVersion() {
		try {
			return ((isAndroid()) ? 1.5F : Float.parseFloat(System
					.getProperty("java.specification.version")));
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		return 1.3F;
	}

	private static boolean isAndroid() {
		return (vendor.indexOf("Android") != -1);
	}
	
}


